﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using WebComponents.Data;
using WebComponents;

public partial class MasterPage : System.Web.UI.MasterPage {
  public string counter = "";
  public string trangchu = "";
  public string lienhe = "";
  public string tintuc = "";
  public string sanpham = "";
  public string gioithieu = "";
  public string currentItems = "";
  protected void Page_Load(object sender, EventArgs e) {
    QuangCao1.Position = "TopBanner";
    QuangCao1.ShowOne = true;
    counter = "0000000" + WebComponents.ConvertType.ToString(Application["Counter"]);
    counter = counter.Substring(counter.Length - 7);
   
    rptCate1.ItemDataBound += new RepeaterItemEventHandler(rptCate1_ItemDataBound);
    rptCate1.DataSource = CategoryController.GetLevel1(WebComponents.CatetoryType.Product);
    rptCate1.DataBind();
    string url = this.Page.ToString().Replace("_", "-").ToLower();
    url = url.Substring(0, url.LastIndexOf("-")) + ".aspx";
    if (url.Contains("san-pham.aspx") || url.Contains("chi-tiet-san-pham.aspx")) {
      sanpham = " active_nav";
      if (url.Contains("chi-tiet-san-pham.aspx")) {
        int cid = ConvertType.ToInt(Request.Params["cid"]);
        if (cid > 0)
          currentItems = "item" + cid.ToString();
      }
    } else if (url.Contains("gioi-thieu.aspx"))
      gioithieu = " active_nav";
    else if (url.Contains("tin-tuc.aspx") || url.Contains("chi-tiet-tin.aspx")) {
      tintuc = " active_nav";

    } else if (url.Contains("lien-he.aspx"))
      lienhe = " active_nav";
    else if (url.Contains("default.aspx"))
      trangchu = " active_nav";

  }

  void rptCate1_ItemDataBound(object sender, RepeaterItemEventArgs e) {
    CategoryInfo c = e.Item.DataItem as CategoryInfo;
    if (c != null) {
      Repeater rpt2 = e.Item.FindControl("rptCate2") as Repeater;
      rpt2.ItemDataBound += new RepeaterItemEventHandler(rpt2_ItemDataBound);
      var list = CategoryController.GetByParentId(WebComponents.CatetoryType.Product, c.CategoryID);
      if (list.Count > 0) {
        rpt2.DataSource = list;
        rpt2.DataBind();
      } else
        rpt2.Visible = false;
    }
  }

  void rpt2_ItemDataBound(object sender, RepeaterItemEventArgs e) {
    CategoryInfo c = e.Item.DataItem as CategoryInfo;
    if (c != null) {
      Repeater rpt3 = e.Item.FindControl("rptCate3") as Repeater;
      var list = CategoryController.GetByParentId(WebComponents.CatetoryType.Product, c.CategoryID);
      if (list.Count > 0) {
        rpt3.DataSource = list;
        rpt3.DataBind();
      } else
        rpt3.Visible = false;
    }
  }
}
